﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class RotationPlatform2 : MonoBehaviour {

    [Header("开始位置")]
    public Vector3 upPosition;
    [Header("开始位置停留时间")]
    public float downDelay = 5f;
    [Header("开始位置到结束位置的动画时间")]
    public float downDuration = 1f;
    [Header("结束位置")]
    public Vector3 downPosition;
    [Header("结束位置停留时间")]
    public float upDelay = 5f;
    [Header("返回开始位置的动画时间")]
    public float upDuration = 1f;

    [Header("顺时针旋转")]
    public bool clockwise;
    [Header("旋转后停留时间")]
    public float rotationDelay = 5f;
    [Header("旋转动画时间")]
    public float rotationDuration = 1f;

    private void Start() {
        transform.localPosition = upPosition;
        OnComplete();
    }

    void OnComplete() {

        transform.DOKill();
        Sequence sequence = DOTween.Sequence();
        sequence.Append(transform.DOLocalMove(downPosition, downDuration)
                        .SetDelay(downDelay));
        sequence.Append(transform.DOLocalRotateQuaternion(Quaternion.Euler(0, 0, clockwise ? -180f : 180f) * transform.localRotation,
                                                          rotationDuration)
                        .SetDelay(rotationDelay));
        sequence.Append(transform.DOLocalMove(upPosition, upDuration)
                        .SetDelay(upDelay));
        sequence.Append(transform.DOLocalRotateQuaternion(Quaternion.Euler(0, 0, clockwise ? -180f : 180f) * transform.localRotation,
                                                          rotationDuration)
                        .SetDelay(rotationDelay));
        sequence.OnComplete(OnComplete);
        sequence.PlayForward();
    }

    [ContextMenu("1.把物体当前位置设置为开始位置")]
    public void CopyPositionToUp() {
        upPosition = transform.localPosition;
    }

    [ContextMenu("2.把物体当前位置设置为结束位置")]
    public void CopyPositionToDown() {
        downPosition = transform.localPosition;
    }

    [ContextMenu("3.让物体移动到开始位置")]
    public void CopyUpToPosition() {
        transform.localPosition = upPosition;
    }

}
